/*
 * @(#)ForumGroupDetail.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.forum.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.dcivision.forum.bean.ForumGroupDetail;
import com.dcivision.forum.web.ListForumGroupDetailForm;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;

/**
  ForumGroupDetailDAObject.java

  This class is the data access bean for table "FORUM_GROUP_DETAIL".

  @author      Zoe Shum
  @company     DCIVision Limited
  @creation date   15/10/2003
  @version     $Revision: 1.21.2.1 $
*/

public class ForumGroupDetailDAObject extends AbstractDAObject {

  public static final String REVISION = "$Revision: 1.21.2.1 $";

  public static final String TABLE_NAME = "FORUM_GROUP_DETAIL";

  public ForumGroupDetailDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }

  
  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("FORUM_GROUP_ID");
    this.vecDBColumn.add("PARENT_ID");
    this.vecDBColumn.add("OBJECT_TYPE");
    this.vecDBColumn.add("OBJECT_ID");
    this.vecDBColumn.add("TOPIC");
    this.vecDBColumn.add("DETAIL");
    this.vecDBColumn.add("ALWAYS_ON_TOP");
    this.vecDBColumn.add("NUM_OF_READS");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }

  
  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.FORUM_GROUP_ID, A.PARENT_ID, A.OBJECT_TYPE, A.OBJECT_ID, A.TOPIC, A.DETAIL, A.ALWAYS_ON_TOP, A.NUM_OF_READS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORUM_GROUP_DETAIL A ");
        sqlStat.append("WHERE  A.ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          ForumGroupDetail tmpForumGroupDetail = new ForumGroupDetail();
          tmpForumGroupDetail.setID(getResultSetInteger(rs, "ID"));
          tmpForumGroupDetail.setForumGroupID(getResultSetInteger(rs, "FORUM_GROUP_ID"));
          tmpForumGroupDetail.setParentID(getResultSetInteger(rs, "PARENT_ID"));
          tmpForumGroupDetail.setObjectType(getResultSetString(rs, "OBJECT_TYPE"));
          tmpForumGroupDetail.setObjectID(getResultSetInteger(rs, "OBJECT_ID"));
          tmpForumGroupDetail.setTopic(getResultSetString(rs, "TOPIC"));
          tmpForumGroupDetail.setDetail(getResultSetString(rs, "DETAIL"));
          tmpForumGroupDetail.setAlwaysOnTop(getResultSetString(rs, "ALWAYS_ON_TOP"));
          tmpForumGroupDetail.setReads(getResultSetInteger(rs, "NUM_OF_READS"));
          tmpForumGroupDetail.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpForumGroupDetail.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpForumGroupDetail.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpForumGroupDetail.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpForumGroupDetail.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpForumGroupDetail.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
          tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
          return(tmpForumGroupDetail);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  
  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());
    ListForumGroupDetailForm forumGroupDetailForm = (ListForumGroupDetailForm)searchForm;
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.FORUM_GROUP_ID, A.PARENT_ID, A.OBJECT_TYPE, A.OBJECT_ID, A.TOPIC, A.DETAIL, A.ALWAYS_ON_TOP, A.NUM_OF_READS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORUM_GROUP_DETAIL A ");
        sqlStat.append("WHERE  A.PARENT_ID = 0 AND A.RECORD_STATUS = ? ");

        if (!Utility.isEmpty(forumGroupDetailForm.getObjectType())){
          sqlStat.append(" AND A.OBJECT_TYPE = ? ");
        }

        if (!Utility.isEmpty(forumGroupDetailForm.getObjectID())){
          sqlStat.append(" AND A.OBJECT_ID = ? ");
        }

        // Form the WHERE clause for filtering.
        if (searchForm.isSearchable()) {
					String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }

        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());

        sqlStat.append("ORDER BY A.ALWAYS_ON_TOP DESC ");
        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append(",  " + sortAttribute + " " + searchForm.getSortOrder());
        }

        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString());
        int i=1;
        this.setPrepareStatement(preStatCnt, i++, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (!Utility.isEmpty(forumGroupDetailForm.getObjectType())){
          this.setPrepareStatement(preStatCnt, i++, forumGroupDetailForm.getObjectType());
        }

        if (!Utility.isEmpty(forumGroupDetailForm.getObjectID())) {
          this.setPrepareStatement(preStatCnt, i++, forumGroupDetailForm.getObjectID());
        }

        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, i++, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }

        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        
        i=1;
        this.setPrepareStatement(preStat, i++, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (!Utility.isEmpty(forumGroupDetailForm.getObjectType())){
          this.setPrepareStatement(preStat, i++, forumGroupDetailForm.getObjectType());
        }

        if (!Utility.isEmpty(forumGroupDetailForm.getObjectID())) {
          this.setPrepareStatement(preStat, i++, forumGroupDetailForm.getObjectID());
        }

        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, i++, searchKeyword);
        }
        rs = preStat.executeQuery();

        this.positionCursor(rs, startOffset, pageSize);

        while (rs.next() && rowLoopCnt<pageSize) {
          ForumGroupDetail tmpForumGroupDetail = new ForumGroupDetail();
          tmpForumGroupDetail.setID(getResultSetInteger(rs, "ID"));
          tmpForumGroupDetail.setForumGroupID(getResultSetInteger(rs, "FORUM_GROUP_ID"));
          tmpForumGroupDetail.setParentID(getResultSetInteger(rs, "PARENT_ID"));
          tmpForumGroupDetail.setObjectType(getResultSetString(rs, "OBJECT_TYPE"));
          tmpForumGroupDetail.setObjectID(getResultSetInteger(rs, "OBJECT_ID"));
          tmpForumGroupDetail.setTopic(getResultSetString(rs, "TOPIC"));
          tmpForumGroupDetail.setDetail(getResultSetString(rs, "DETAIL"));
          tmpForumGroupDetail.setAlwaysOnTop(getResultSetString(rs, "ALWAYS_ON_TOP"));
          tmpForumGroupDetail.setReads(getResultSetInteger(rs, "NUM_OF_READS"));
          tmpForumGroupDetail.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpForumGroupDetail.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpForumGroupDetail.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpForumGroupDetail.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpForumGroupDetail.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpForumGroupDetail.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
          tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
          tmpForumGroupDetail.setRecordCount(totalNumOfRecord);
          tmpForumGroupDetail.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpForumGroupDetail);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }

  
  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.FORUM_GROUP_ID, A.PARENT_ID, A.OBJECT_TYPE, A.OBJECT_ID, A.TOPIC, A.DETAIL, A.ALWAYS_ON_TOP, A.NUM_OF_READS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORUM_GROUP_DETAIL A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          ForumGroupDetail tmpForumGroupDetail = new ForumGroupDetail();
          tmpForumGroupDetail.setID(getResultSetInteger(rs, "ID"));
          tmpForumGroupDetail.setForumGroupID(getResultSetInteger(rs, "FORUM_GROUP_ID"));
          tmpForumGroupDetail.setParentID(getResultSetInteger(rs, "PARENT_ID"));
          tmpForumGroupDetail.setObjectType(getResultSetString(rs, "OBJECT_TYPE"));
          tmpForumGroupDetail.setObjectID(getResultSetInteger(rs, "OBJECT_ID"));
          tmpForumGroupDetail.setTopic(getResultSetString(rs, "TOPIC"));
          tmpForumGroupDetail.setDetail(getResultSetString(rs, "DETAIL"));
          tmpForumGroupDetail.setAlwaysOnTop(getResultSetString(rs, "ALWAYS_ON_TOP"));
          tmpForumGroupDetail.setReads(getResultSetInteger(rs, "NUM_OF_READS"));
          tmpForumGroupDetail.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpForumGroupDetail.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpForumGroupDetail.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpForumGroupDetail.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpForumGroupDetail.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpForumGroupDetail.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
          tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
          result.add(tmpForumGroupDetail);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  
  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }

  
  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }

  
  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }

  
  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    ForumGroupDetail tmpForumGroupDetail = (ForumGroupDetail)((ForumGroupDetail)obj).clone();

    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        sqlStat.append("INTO   FORUM_GROUP_DETAIL(ID, FORUM_GROUP_ID, PARENT_ID, OBJECT_TYPE, OBJECT_ID, TOPIC, DETAIL, ALWAYS_ON_TOP, NUM_OF_READS, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, nextID);
//log.debug("next ID + " + nextID);
        setPrepareStatement(preStat, 2, tmpForumGroupDetail.getForumGroupID());
        setPrepareStatement(preStat, 3, tmpForumGroupDetail.getParentID());
        setPrepareStatement(preStat, 4, tmpForumGroupDetail.getObjectType());
        setPrepareStatement(preStat, 5, tmpForumGroupDetail.getObjectID());
        setPrepareStatement(preStat, 6, tmpForumGroupDetail.getTopic());
        setPrepareStatement(preStat, 7, tmpForumGroupDetail.getDetail());
        setPrepareStatement(preStat, 8, tmpForumGroupDetail.getAlwaysOnTop());
        setPrepareStatement(preStat, 9, tmpForumGroupDetail.getReads());
        setPrepareStatement(preStat, 10, GlobalConstant.RECORD_STATUS_ACTIVE);
        setPrepareStatement(preStat, 11, new Integer(0));
        setPrepareStatement(preStat, 12, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 13, currTime);
        setPrepareStatement(preStat, 14, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 15, currTime);
        preStat.executeUpdate();
        tmpForumGroupDetail.setID(nextID);
        tmpForumGroupDetail.setCreatorID(sessionContainer.getUserRecordID());
        tmpForumGroupDetail.setCreateDate(currTime);
        tmpForumGroupDetail.setUpdaterID(sessionContainer.getUserRecordID());
        tmpForumGroupDetail.setUpdateDate(currTime);
        tmpForumGroupDetail.setUpdateCount(new Integer(0));
        tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
        tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
        return(tmpForumGroupDetail);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  
  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    ForumGroupDetail tmpForumGroupDetail = (ForumGroupDetail)((ForumGroupDetail)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE FORUM_GROUP_DETAIL ");
        sqlStat.append("SET  FORUM_GROUP_ID=?, PARENT_ID=?, OBJECT_TYPE=?, OBJECT_ID=?, TOPIC=?, DETAIL=?, ALWAYS_ON_TOP=?, NUM_OF_READS=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpForumGroupDetail.getForumGroupID());
        setPrepareStatement(preStat, 2, tmpForumGroupDetail.getParentID());
        setPrepareStatement(preStat, 3, tmpForumGroupDetail.getObjectType());
        setPrepareStatement(preStat, 4, tmpForumGroupDetail.getObjectID());
        setPrepareStatement(preStat, 5, tmpForumGroupDetail.getTopic());
        setPrepareStatement(preStat, 6, tmpForumGroupDetail.getDetail());
        setPrepareStatement(preStat, 7, tmpForumGroupDetail.getAlwaysOnTop());
        setPrepareStatement(preStat, 8, tmpForumGroupDetail.getReads());
        setPrepareStatement(preStat, 9, new Integer(tmpForumGroupDetail.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 10, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 11, currTime);
        setPrepareStatement(preStat, 12, tmpForumGroupDetail.getID());
        setPrepareStatement(preStat, 13, tmpForumGroupDetail.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpForumGroupDetail.setUpdaterID(sessionContainer.getUserRecordID());
          tmpForumGroupDetail.setUpdateDate(currTime);
          tmpForumGroupDetail.setUpdateCount(new Integer(tmpForumGroupDetail.getUpdateCount().intValue() + 1));
          tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
          tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
          return(tmpForumGroupDetail);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  
  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    ForumGroupDetail tmpForumGroupDetail = (ForumGroupDetail)((ForumGroupDetail)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   FORUM_GROUP_DETAIL ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpForumGroupDetail.getID());
        setPrepareStatement(preStat, 2, tmpForumGroupDetail.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpForumGroupDetail);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  
  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    ForumGroupDetail tmpForumGroupDetail = (ForumGroupDetail)this.oldValue;

    if (tmpForumGroupDetail != null) {
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getID()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getForumGroupID()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getParentID()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getObjectType()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getObjectID()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getTopic()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getDetail()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getAlwaysOnTop()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getReads()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpForumGroupDetail.getUpdateDate()));
    }

    tmpForumGroupDetail = (ForumGroupDetail)obj;
    if (tmpForumGroupDetail != null) {
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getID()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getForumGroupID()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getParentID()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getObjectType()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getObjectID()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getTopic()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getDetail()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getAlwaysOnTop()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getReads()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpForumGroupDetail.getUpdateDate()));
    }

    auditTrailBase(opMode, oldValues, newValues);
  }

  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/
  public synchronized Integer getReplyTotal(Integer discussParentID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    Integer replyTotal=new Integer (0);

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT COUNT(*) AS REPLIES ");
        sqlStat.append("FROM   FORUM_GROUP_DETAIL A ");
        sqlStat.append("WHERE  (PARENT_ID = ?) AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, discussParentID);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          replyTotal = getResultSetInteger(rs, "REPLIES");
        }
        return(replyTotal);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  public synchronized List getReplyList(String parentID, String objectType, String objectID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT DISTINCT(A.ID), A.FORUM_GROUP_ID, A.PARENT_ID, A.OBJECT_TYPE, A.OBJECT_ID, A.TOPIC, A.DETAIL, A.ALWAYS_ON_TOP, A.NUM_OF_READS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORUM_GROUP_DETAIL A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND OBJECT_TYPE = ? AND OBJECT_ID = ? ");
        if(!Utility.isEmpty(parentID)){
          sqlStat.append(" AND PARENT_ID = ? ");
        }else{
          sqlStat.append(" AND PARENT_ID <> ? "); 
        }
        sqlStat.append("ORDER BY A.ID DESC ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, objectType);
        this.setPrepareStatement(preStat, 3, objectID);
        if(!Utility.isEmpty(parentID)){
          this.setPrepareStatement(preStat, 4, parentID);
        }else{
          this.setPrepareStatement(preStat, 4, new Integer(0)); 
        }
        rs = preStat.executeQuery();
        while (rs.next()) {
          ForumGroupDetail tmpForumGroupDetail = new ForumGroupDetail();
          tmpForumGroupDetail.setID(getResultSetInteger(rs, "ID"));
          tmpForumGroupDetail.setForumGroupID(getResultSetInteger(rs, "FORUM_GROUP_ID"));
          tmpForumGroupDetail.setParentID(getResultSetInteger(rs, "PARENT_ID"));
          tmpForumGroupDetail.setObjectType(getResultSetString(rs, "OBJECT_TYPE"));
          tmpForumGroupDetail.setObjectID(getResultSetInteger(rs, "OBJECT_ID"));
          tmpForumGroupDetail.setTopic(getResultSetString(rs, "TOPIC"));
          tmpForumGroupDetail.setDetail(getResultSetString(rs, "DETAIL"));
          tmpForumGroupDetail.setAlwaysOnTop(getResultSetString(rs, "ALWAYS_ON_TOP"));
          tmpForumGroupDetail.setReads(getResultSetInteger(rs, "NUM_OF_READS"));
          tmpForumGroupDetail.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpForumGroupDetail.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpForumGroupDetail.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpForumGroupDetail.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpForumGroupDetail.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpForumGroupDetail.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
          tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
          result.add(tmpForumGroupDetail);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  public synchronized ForumGroupDetail getLastestReplied(String parentID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    ForumGroupDetail tmpForumGroupDetail = new ForumGroupDetail();
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.FORUM_GROUP_ID, A.PARENT_ID, A.OBJECT_TYPE, A.OBJECT_ID, A.TOPIC, A.DETAIL, A.ALWAYS_ON_TOP, A.NUM_OF_READS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   FORUM_GROUP_DETAIL A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND PARENT_ID = ? ");
        sqlStat.append("ORDER BY A.CREATE_DATE DESC ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, parentID);
        rs = preStat.executeQuery();
        if (rs.next()) {
          tmpForumGroupDetail.setID(getResultSetInteger(rs, "ID"));
          tmpForumGroupDetail.setForumGroupID(getResultSetInteger(rs, "FORUM_GROUP_ID"));
          tmpForumGroupDetail.setParentID(getResultSetInteger(rs, "PARENT_ID"));
          tmpForumGroupDetail.setObjectType(getResultSetString(rs, "OBJECT_TYPE"));
          tmpForumGroupDetail.setObjectID(getResultSetInteger(rs, "OBJECT_ID"));
          tmpForumGroupDetail.setTopic(getResultSetString(rs, "TOPIC"));
          tmpForumGroupDetail.setDetail(getResultSetString(rs, "DETAIL"));
          tmpForumGroupDetail.setAlwaysOnTop(getResultSetString(rs, "ALWAYS_ON_TOP"));
          tmpForumGroupDetail.setReads(getResultSetInteger(rs, "NUM_OF_READS"));
          tmpForumGroupDetail.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpForumGroupDetail.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpForumGroupDetail.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpForumGroupDetail.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpForumGroupDetail.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpForumGroupDetail.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
          tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
          return(tmpForumGroupDetail);
        }else{
          return null;
        }

      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  public synchronized List getForumGroupDetailListByObjectTypeObjectID(String objectType, Integer objectID) throws ApplicationException {
    return this.getForumGroupDetailListByObjectTypeObjectID(objectType,objectID,null);
  }
  
  public synchronized List getForumGroupDetailListByObjectTypeObjectID(String objectType, Integer objectID,Integer parentID) throws ApplicationException {
     PreparedStatement preStat = null;
     ResultSet rs = null;
     StringBuffer sqlStat = new StringBuffer();
     List result = new ArrayList();

     synchronized(dbConn) {
       try {
         sqlStat.append("SELECT DISTINCT(A.ID), A.FORUM_GROUP_ID, A.PARENT_ID, A.OBJECT_TYPE, A.OBJECT_ID, A.TOPIC, A.DETAIL, A.ALWAYS_ON_TOP, A.NUM_OF_READS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
         sqlStat.append("FROM   FORUM_GROUP_DETAIL A ");
         sqlStat.append("WHERE  A.RECORD_STATUS = ? AND OBJECT_TYPE = ? AND OBJECT_ID = ? ");
//         sqlStat.append("ORDER BY A.ID ASC ");
         if(!Utility.isEmpty(parentID)){
           sqlStat.append(" AND PARENT_ID= ? ");
         }
         preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
         this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
         this.setPrepareStatement(preStat, 2, objectType);
         this.setPrepareStatement(preStat, 3, objectID);
         if(!Utility.isEmpty(parentID)){
           this.setPrepareStatement(preStat, 4, parentID);
         }
         rs = preStat.executeQuery();
         while (rs.next()) {
           ForumGroupDetail tmpForumGroupDetail = new ForumGroupDetail();
           tmpForumGroupDetail.setID(getResultSetInteger(rs, "ID"));
           tmpForumGroupDetail.setForumGroupID(getResultSetInteger(rs, "FORUM_GROUP_ID"));
           tmpForumGroupDetail.setParentID(getResultSetInteger(rs, "PARENT_ID"));
           tmpForumGroupDetail.setObjectType(getResultSetString(rs, "OBJECT_TYPE"));
           tmpForumGroupDetail.setObjectID(getResultSetInteger(rs, "OBJECT_ID"));
           tmpForumGroupDetail.setTopic(getResultSetString(rs, "TOPIC"));
           tmpForumGroupDetail.setDetail(getResultSetString(rs, "DETAIL"));
           tmpForumGroupDetail.setAlwaysOnTop(getResultSetString(rs, "ALWAYS_ON_TOP"));
           tmpForumGroupDetail.setReads(getResultSetInteger(rs, "NUM_OF_READS"));
           tmpForumGroupDetail.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
           tmpForumGroupDetail.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
           tmpForumGroupDetail.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
           tmpForumGroupDetail.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
           tmpForumGroupDetail.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
           tmpForumGroupDetail.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
           tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
           tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
           result.add(tmpForumGroupDetail);
         }
         return(result);
       } catch (ApplicationException appEx) {
         throw appEx;
       } catch (SQLException sqle) {
         log.error(sqle, sqle);
         throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
       } catch (Exception e) {
         log.error(e, e);
         throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
       } finally {
         try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
         try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
       }
     }
   }
   
   public synchronized List getInactiveForumGroupDetailListByObjectTypeObjectID(String objectType, Integer objectID) throws ApplicationException {
     PreparedStatement preStat = null;
	     ResultSet rs = null;
	     StringBuffer sqlStat = new StringBuffer();
	     List result = new ArrayList();

	     synchronized(dbConn) {
	       try {
	         sqlStat.append("SELECT DISTINCT(A.ID), A.FORUM_GROUP_ID, A.PARENT_ID, A.OBJECT_TYPE, A.OBJECT_ID, A.TOPIC, A.DETAIL, A.ALWAYS_ON_TOP, A.NUM_OF_READS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
	         sqlStat.append("FROM   FORUM_GROUP_DETAIL A ");
	         sqlStat.append("WHERE  A.RECORD_STATUS = ? AND OBJECT_TYPE = ? AND OBJECT_ID = ? ");
         //					 sqlStat.append("ORDER BY A.ID ASC ");
	         preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
	         this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_INACTIVE);
	         this.setPrepareStatement(preStat, 2, objectType);
	         this.setPrepareStatement(preStat, 3, objectID);
	         rs = preStat.executeQuery();
	         while (rs.next()) {
	           ForumGroupDetail tmpForumGroupDetail = new ForumGroupDetail();
		           tmpForumGroupDetail.setID(getResultSetInteger(rs, "ID"));
		           tmpForumGroupDetail.setForumGroupID(getResultSetInteger(rs, "FORUM_GROUP_ID"));
		           tmpForumGroupDetail.setParentID(getResultSetInteger(rs, "PARENT_ID"));
		           tmpForumGroupDetail.setObjectType(getResultSetString(rs, "OBJECT_TYPE"));
		           tmpForumGroupDetail.setObjectID(getResultSetInteger(rs, "OBJECT_ID"));
		           tmpForumGroupDetail.setTopic(getResultSetString(rs, "TOPIC"));
		           tmpForumGroupDetail.setDetail(getResultSetString(rs, "DETAIL"));
		           tmpForumGroupDetail.setAlwaysOnTop(getResultSetString(rs, "ALWAYS_ON_TOP"));
		           tmpForumGroupDetail.setReads(getResultSetInteger(rs, "NUM_OF_READS"));
		           tmpForumGroupDetail.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
		           tmpForumGroupDetail.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
		           tmpForumGroupDetail.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
		           tmpForumGroupDetail.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
		           tmpForumGroupDetail.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
		           tmpForumGroupDetail.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
		           tmpForumGroupDetail.setCreatorName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getCreatorID()));
		           tmpForumGroupDetail.setUpdaterName(UserInfoFactory.getUserFullName(tmpForumGroupDetail.getUpdaterID()));
		           result.add(tmpForumGroupDetail);
		         }
		         return(result);
		       } catch (ApplicationException appEx) {
		         throw appEx;
		       } catch (SQLException sqle) {
		         log.error(sqle, sqle);
		         throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
		       } catch (Exception e) {
		         log.error(e, e);
		         throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
		       } finally {
		         try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
		         try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
		       }
	     }
   }
     
	public synchronized void hardDelete(AbstractBaseObject obj) throws ApplicationException {
	  PreparedStatement preStat = null;
	  StringBuffer sqlStat = new StringBuffer();
	  ForumGroupDetail tmpForumGroupDetail = (ForumGroupDetail)((ForumGroupDetail)obj).clone();
    
	  synchronized(dbConn) {
	    try {
	      int updateCnt = 0;
		    sqlStat.append("DELETE ");
		    sqlStat.append("FROM   FORUM_GROUP_DETAIL ");
		    sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
		    preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
		    setPrepareStatement(preStat, 1, tmpForumGroupDetail.getID());
		    setPrepareStatement(preStat, 2, tmpForumGroupDetail.getUpdateCount());
		    updateCnt = preStat.executeUpdate();
		
  		} catch (SQLException sqle) {
		    log.error(sqle, sqle);
			  throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
		  } catch (Exception e) {
			  log.error(e, e);
			  throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
		  } finally {
		    try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
		  }
		}
	} 
 
}
